package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.TokenDao;
import com.qf.entity.Token;
import com.qf.service.TokenService;
import com.qf.service.TokenService;
import com.qf.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenDao tokenDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Token findToken(Integer id) {
        return tokenDao.findTokenById(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Token> findAll() {
        PageHelper.startPage(1,2);
        return tokenDao.findAllTokens();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<Token> findAll(PageVo pageVo) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<Token> tokens = tokenDao.findAllTokens();
        return new PageInfo<Token>(tokens);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<Token> findAll(PageVo pageVo, Token token) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<Token> tokens = tokenDao.findAllTokensByConfition(token);
        return new PageInfo<Token>(tokens);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer addToken(Token token) {
        return tokenDao.insertToken(token);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer delToken(Integer[] ids) {
        return tokenDao.deleteToken(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateToken(Token token) {
        return tokenDao.updateToken(token);
    }
}
